package com.xfs.dao.impl;
import com.xfs.dao.EmployeeDAO;
import com.xfs.utils.PasswordUtil;


import com.xfs.entity.Employee;
import com.xfs.service.EmployeeService;

import com.xfs.utils.SystemConstant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author dwj
 * @Date 2021-09-04 15:35
 */

@Service
@Transactional
public class EmployeeDAOImpl implements EmployeeService {
    @Resource
    private EmployeeDAO employeeDAO;

    /**
     * 员工登录
     *
     * @param loginName
     * @param loginPassword
     * @return
     */
    public Employee login(String loginName, String loginPassword) {
        // 根据账号查询信息的方法
        Employee employee = employeeDAO.findEmployeeByLoginName(loginName);
        // 判断是否为空
        if (employee != null) {
            // 将密码加密处理
            String newPassword = PasswordUtil.md5(loginPassword, employee.getSalt(), SystemConstant.PASSWORD_COUNT);
            // 比较密码是否一致
            if (employee.getLoginPassword().equals(newPassword)) {
                return employee;     // 登录成功
            }
        }
        // 登录失败
        return null;
    }
}
